//
//  UserFollow.m
//  XPhoto
//
//  Created by baboy on 2019/8/9.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "UserFollow.h"
#import <BKKit/BKApi.h>
#import "HttpResponse.h"

@implementation UserFollow

+ (id)searchFans:(UserFollowSearchArgs *)args callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    
    return [BKApi request:API_FRIENDSHIP_FAN_SEARCH
             parameters:args
               callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                   User *user = nil;
                   if (!error && json) {
                       HttpResponse *response = [HttpResponse responseWithDictionary:json dataItemClass:[User class]];
                       if ([response isSuccess]) {
                           user = response.data;
                       }
                       if (![response isSuccess]) {
                           error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                       }
                   }
                   callback(task, user, error);
               }];
}
+ (id)searchFollows:(UserFollowSearchArgs *)args callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    
    return [BKApi request:API_FRIENDSHIP_FOLLOW_SEARCH
             parameters:args
               callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                   User *user = nil;
                   if (!error && json) {
                       HttpResponse *response = [HttpResponse responseWithDictionary:json dataItemClass:[User class]];
                       if ([response isSuccess]) {
                           user = response.data;
                       }
                       if (![response isSuccess]) {
                           error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                       }
                   }
                   callback(task, user, error);
               }];
}

+ (id)addFollow:(NSInteger)followUid callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    
    id param = @{@"followUid": [NSNumber numberWithLong:followUid]};
    return [BKApi request:API_FRIENDSHIP_FOLLOW
             parameters:param
               callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                   if (!error && json) {
                       HttpResponse *response = [HttpResponse responseWithDictionary:json dataItemClass:[UserFollow class]];
                       if (![response isSuccess]) {
                           error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                       }
                   }
                   callback(task, nil, error);
               }];
}

+ (id)removeFollow:(NSInteger)followUid callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    
    id param = @{@"followUid": [NSNumber numberWithLong:followUid]};
    return [BKApi request:API_FRIENDSHIP_UNFOLLOW
             parameters:param
               callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                   if (!error && json) {
                       HttpResponse *response = [HttpResponse responseWithDictionary:json dataItemClass:[UserFollow class]];
                       if (![response isSuccess]) {
                           error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                       }
                   }
                   callback(task, nil, error);
               }];
}
@end

@implementation UserFollowSearchArgs

@end
